"""
行为树-黑板- 过滤关键字
"""

import py_trees

if __name__ == "__main__":
    # 创建黑板关键字
    writer = py_trees.blackboard.Client(name="Writer")
    for key in {"foo", "bar", "dude", "dudette"}:
        writer.register_key(key=key, access=py_trees.common.Access.WRITE)

    reader = py_trees.blackboard.Client(name="Reader")
    for key in {"foo", "bar"}:
        reader.register_key(key=key, access=py_trees.common.Access.READ)

    # 写入黑板
    writer.foo = "Hello"
    writer.bar = "World"
    writer.dude = "abc"
    writer.dudette = "def"

    # 过滤关键字
    all_key_value = py_trees.display.unicode_blackboard()  # 全部关键字
    print(all_key_value)
    key_filter = py_trees.display.unicode_blackboard(key_filter={"foo"})  # 过滤关键字
    print(key_filter)
    regex_filter = py_trees.display.unicode_blackboard(regex_filter="dude*")  # 正则表达式 过滤
    print(regex_filter)

    # 打印客户端关键字
    client_key = py_trees.display.unicode_blackboard(client_filter={reader.unique_identifier})
    print(client_key)
    # 打印所有客户端关键字 + 读写属性
    all_client_key = py_trees.display.unicode_blackboard(display_only_key_metadata=True)
    print(all_client_key)

""" 
Blackboard Data
    /bar    : World
    /dude   : abc
    /dudette: def
    /foo    : Hello

Blackboard Data
  Filter: '{'foo'}'

Blackboard Data
  Filter: 'dude*'
    /dude   : abc
    /dudette: def
"""


"""
Blackboard Data
  Filter: {UUID('ae7bc80c-f08b-4493-a584-b65b6e8379cf')}
    /bar: World
    /foo: Hello

Blackboard Clients
    /bar     : Writer (w), Reader (r)
    /dude    : Writer (w)
    /dudette : Writer (w)
    /foo     : Writer (w), Reader (r)
"""
